<?php

/**
 * MVM_MALL 网上商店系统  公告牌列表
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-06-14 $
 * $Id: board.php  www.mvmmall.com$
 * ---------------------------------------------
*/

require_once 'include/common.inc.php';
require_once MVMMALL_ROOT . 'header.php';
require_once MVMMALL_ROOT.'include/pager.class.php';
require_once MVMMALL_ROOT.'include/board_comm.inc.php';
/**目录查看权限**/
$m_check_rank < $mm_board['class_list'] && show_msg('board_grant_list_member');

/**判断是否开通搜索功能**/
$search_sql = false;
if ($mm_board['use_search'] && $ps_sele && $ps_ques) {
    $ps_ques  = trim(strtr($ps_ques, array("\\\\" => "\\\\\\\\", '_' => '\_', '%' => '\%')));
    switch ($ps_sele)
    {
    	case 'subject':
    	{
    		$search_sql = " board_subject LIKE '%$ps_ques%' ";
    		break;
    	}
    	case 'content':
    	{
    		$search_sql = " board_body LIKE '%$ps_ques%' ";
    		break;
    	}
    	case 'name':
    	{
    		$search_sql = " board_name LIKE '%$ps_ques%' ";
    		break;
    	}
    	case 'sub_plus':
    	{
    		$search_sql = " board_subject LIKE '%$ps_ques%' AND board_body LIKE '%$ps_ques%' ";
    		break;
    	}
    	default:
    	{
    		$search_sql = '';
    		break;
    	}
    }
}
$search_sql = $search_sql? 'WHERE'.$search_sql ." AND ps_name='$action'" : "WHERE ps_name='$action'";
/**end**/

//我的留言
if($my_board=='1'&&isset($m_check_id)){
    $search_sql             .= "AND board_id='$m_check_id'";
    $mm_board['board_title'] = $lang['my_freeboard'];
}

//文章列表
$total_count = $db->counter("{$tablepre}bmain",$search_sql);
$page        = (int)$page;
$list_num    = $mm_board['list_num'];
$rowset      = new Pager($total_count,$list_num,$page);
$from_record = $rowset->_offset();
$result      = $db->query("SELECT a.* ,b.register_date AS reply_date,b.fid,COUNT(distinct a.uid) FROM `{$tablepre}bmain` a LEFT JOIN `{$tablepre}bcomment` b  ON a.uid=b.fid $search_sql  GROUP BY a.headnum ASC  LIMIT $from_record,$list_num");
while($rt = $db->fetch_array($result)) {
	$rt['date']      = date($mm_date_format,$rt['register_date']);
	$rt['check_uid'] = $m_check_rank >= $mm_board['class_list']?"<input type=\"checkbox\" name=\"uid_check[]\" value=\"$rt[uid]\">":false;
	$mm_board['str_length'] && $rt['subject'] = cut_str($rt['board_subject'],$mm_board['str_length']);
	$rt['headnum'] < 1000 && $rt['subject'] = "<img src=\"$imgpath/icon_com.gif\"  border=\"0\" alt=\"$lang[uesr_top]\">".$rt['subject'];
    $rt['author']    = str_replace("\"./","\"",$rt['board_name']);
	$rt['category']  = ($rt['board_category'] && $mm_board['use_category'] == '1') ? '['.$show_category_array[$rt['board_category']].']':'';
	//有回复显示new处理
	if ($rt['reply_date']){
		$_COOKIE['mvm_reply'][$rt['uid']]['time']<$rt['reply_date'] && $rt['subject'].='<font color=\"Green\"> New</font>';
	}else if ($_COOKIE['mvm_reply'][$rt[uid]]['id']!=$rt['uid']){
		$rt['subject'].='<font color=\"Green\"> New</font>';
	}
	$rt['title']  = $rt['board_subject'];
	// 悄悄话图标
	$rt['secret'] = $rt['use_secret']==1 ? "<img src=\"$imgpath/board_secret.gif\" border=\"0\">":"";
	$rt['url']    = $rewrite==1 ? "article-$action-$rt[uid].html":"article.php?action=$action&id=$rt[uid]";
	$rt['hit']    = $rt['board_hit'];
	$board_list[]   = $rt;
}
//end

$m_check_rank >= $mm_board['class_list'] && $del_url  = "<a href=\"#\" onclick=\"really_all()\"><input type=\"button\" value=\"$lang[uesr_del]\" class=\"btn2\"/></a>";

if($my_board=='1'&&isset($m_check_id)){
	$baseurl    = "board.php?action=$action&my_board=1&page=";
}elseif ($rewrite == 1){
	$baseurl = str_replace('1.html','',GetBaseUrl('board',$action));
	$exc        ='.html';
}else {
	$baseurl    = GetBaseUrl('board',$action).'&page=';
}
$page_list      = $rowset->link($baseurl, $exc);
$navigation     = make_navigation($mm_board['board_title'],$baseurl.$page.$exc);//导航
$formula_list   = $mm_board['formula'];
$board_post_url = "post.php?action=$action&ps_mode=write";

$mm_mall_title  =  $mm_board['board_title']; //标题
$mm_keywords    = $mm_board['board_title'].$mm_keywords; //关键字
$mm_board['desc_text'] && $mm_description = $mm_board['desc_text']; //描述
require_once template('board_list');
footer();